package model;

import static org.junit.Assert.*;

import java.math.BigDecimal;

import org.junit.Test;

import exceptions.BidLessThanMinBidException;
import exceptions.BidderNotRegisteredException;
import exceptions.DuplicateBidException;

//Spring 2012 TCSS360 Deliverable 3
//Otis Alexander

public class ItemTest {

	Item item = new Item(null, 1, new BigDecimal(2), Integer.toString(0), null, null, 1);
	Bidder bidder = new Bidder(null, null, null);

	@Test(expected = BidderNotRegisteredException.class)
	public void testBiddingNoCreditCardRegistered() throws BidLessThanMinBidException,
			BidderNotRegisteredException, DuplicateBidException {
		item.placeBid(new BigDecimal(2), bidder);
	}
	
	@Test
	public void testBiddingWithCreditCardRegistered() throws BidLessThanMinBidException,
			BidderNotRegisteredException, DuplicateBidException {
		assertEquals(0, bidder.getBids().size());
		bidder.setCreditCard("123455869589585");
		item.placeBid(new BigDecimal(2), bidder);
		assertEquals(1, bidder.getBids().size());
	}

	@Test(expected = BidLessThanMinBidException.class)
	public void testBidLowerThanMinBid() throws BidLessThanMinBidException,
			BidderNotRegisteredException, DuplicateBidException {
		bidder.setCreditCard("1234567812345678");
		item.placeBid(new BigDecimal(1), bidder);
	}
	
	@Test
	public void testBidAtMinBid() throws BidLessThanMinBidException,
			BidderNotRegisteredException, DuplicateBidException {
		bidder.setCreditCard("1234567812345678");
		item.placeBid(new BigDecimal(2), bidder);
		assertEquals(new BigDecimal(2), bidder.getBids().get(item));
	}
	
	@Test
	public void testBidHigherThanMinBid() throws BidLessThanMinBidException,
			BidderNotRegisteredException, DuplicateBidException {
		bidder.setCreditCard("1234567812345678");
		item.placeBid(new BigDecimal(3), bidder);
		assertEquals(new BigDecimal(3), bidder.getBids().get(item));
	}

	@Test(expected = DuplicateBidException.class)
	public void testBidTwiceOnSameItem() throws BidLessThanMinBidException,
			BidderNotRegisteredException, DuplicateBidException {
		bidder.setCreditCard("1234567812345678");
		item.placeBid(new BigDecimal(2), bidder);
		item.placeBid(new BigDecimal(3), bidder);
	}
}
